package com.woniuxy.controller;

import com.woniuxy.entity.ClazzRoom;
import com.woniuxy.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: 马宇航
 * @Todo: 用于接收，前端form表单传来的各类参数
 * @DateTime: 22/01/24/0024 下午 3:59
 * @Component: 成都蜗牛学苑
 **/
@Controller
@RequestMapping("/form")
public class FormSendParamsController {
    /**
     * @Todo: 接收字符串传参！
     * ChangeLog : 1. 创建 (22/01/24/0024 下午 4:00 [马宇航]);
     * @param name
     * @return org.springframework.web.servlet.ModelAndView
    */
    @RequestMapping("/StringValue")
    public ModelAndView receiveParameters(String name){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+name);
        modelAndView.setViewName("myTest");
        return modelAndView;
    }
    /**
     * @Todo: 接收前端form提交的数组
     * ChangeLog : 1. 创建 (22/01/24/0024 下午 4:11 [马宇航]);
     * @param ids
     * @return org.springframework.web.servlet.ModelAndView
    */
    @RequestMapping("/ArrayValue")
    public ModelAndView receiveParameters(String[] ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ Arrays.toString(ids));
        modelAndView.setViewName("myTest");
        return modelAndView;
    }
    /**
     * @Todo: 传入一个数组，后端自动封装成List集合
     * ChangeLog : 1. 创建 (22/01/24/0024 下午 4:49 [马宇航]);
     * @param ids
     * @return org.springframework.web.servlet.ModelAndView
    */
    @RequestMapping("/ListValue")
    public ModelAndView receiveParameters(@RequestParam List<Integer> ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ ids);
        modelAndView.setViewName("myTest");
        return modelAndView;
    }
    /**
     * @Todo: 传入一堆数据，后端自动封装成Map集合
     * ChangeLog : 1. 创建 (22/01/24/0024 下午 4:59 [马宇航]);
     * @param user
     * @return org.springframework.web.servlet.ModelAndView
    */
    @RequestMapping("/MapValue")
    public ModelAndView receiveParameters(@RequestParam Map<String,Object> user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ user.toString());
        modelAndView.setViewName("myTest");
        return modelAndView;
    }
    /**
     * @Todo: 传入一堆数据，后端自动封装成User对象
     * ChangeLog : 1. 创建 (22/01/24/0024 下午 5:13 [马宇航]);
     * @param user
     * @return org.springframework.web.servlet.ModelAndView
    */
    @RequestMapping("/UserValue")
    public ModelAndView receiveParameters(User user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ user.toString());
        modelAndView.setViewName("myTest");
        return modelAndView;
    }
    /**
     * @Todo: 复合对象数据传输
     * ChangeLog : 1. 创建 (22/01/24/0024 下午 5:17 [马宇航]);
     * @param clazzRoom
     * @return org.springframework.web.servlet.ModelAndView
    */
    @RequestMapping("/ClazzUserValue")
    public ModelAndView receiveParameters(ClazzRoom clazzRoom){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ clazzRoom.toString());
        modelAndView.setViewName("myTest");
        return modelAndView;
    }
}
